import React, {useState} from "react";
import {Button, Grid} from "@material-ui/core";
import {AddRounded, PublishRounded} from "@material-ui/icons";

import {EnhancedTable, Toolbar} from "../../../shared/components";
import {getTools} from "../../../shared/services/data.service";

const ViewAllToolInventory = ({onAdd, onRowClick, ...props}) => {
    const [toolList, setToolList] = useState([]);

    const getToolList = () => (
        new Promise((resolve, reject) => {
            getTools().then(res => {
                resolve([]);
                setToolList([]);
            }).catch(error => reject(error));
        })
    );

    return (
        <Grid container spacing={4}>
            <Toolbar
                title="Check-In Check-Out"
                actions={<React.Fragment>
                    <Button variant="contained" color="primary" startIcon={<AddRounded/>} onClick={onAdd}>Add Tool</Button>
                    <Button variant="outlined" startIcon={<PublishRounded/>}>Bulk Upload</Button>
                </React.Fragment>}
            />
            <Grid item xs={12}>
                <EnhancedTable
                    title={"Tool List"}
                    schema={[
                        {id: 'id', label: 'Id', hidden: true},
                        {id: 'serialNumber', label: 'Serial No.', sort: true},
                        {id: 'toolName', label: 'Name', sort: true},
                        {id: 'type', label: 'Type', sort: true},
                        {id: 'quantity', label: 'Quantity', sort: true},
                        {id: 'status', label: 'Status', sort: true},
                        {id: 'Location', label: 'Location', sort: true},
                        {id: 'manufacture', label: 'Manufacture', sort: true}
                    ]}
                    data={toolList}
                    async={{loading: true, loadingData: getToolList}}
                    pagination={toolList.length > 5}
                    onRowClick={onRowClick}
                />
            </Grid>
        </Grid>
    );
};

export default ViewAllToolInventory;
